package datastructure.hash.leetcode;

/**
 * @Description: leetcode第387题
 * @author: Yang Qiang
 * @create: 2021-11-27 15:13
 */
public class Solution {
    public static void main(String[] args) {
        // 打印的0
        System.out.println(firstUniqChar("leetcode"));

    }
    public static int firstUniqChar(String s) {
        int[] charArray = new int[26];
        for (int i = 0; i < s.length(); i++) {
            // s.charAt(0) = l = 108
            // l在ASCLL码表 = 代表108
            charArray[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            if (charArray[s.charAt(i) - 'a'] == 1){
                return i;
            }
        }
        return -1;
    }
}
